using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using FBGraph.Demos.AspNetMvc.Models.View.Search;

namespace FBGraph.Demos.AspNetMvc.Controllers
{
    public class SearchController : BaseController
    {
        public ActionResult Index(String query)
        {
            using (var async = FbContext.StartAsync())
            {
                var posts = FbContext.Posts.Search(query);
                var people = FbContext.Users.Search(query);
                var pages = FbContext.Pages.Search(query);
                var events = FbContext.Events.Search(query);
                var groups = FbContext.Groups.Search(query);
                var feed = FbContext.Users.Home.Search(query);

                FbContext.CompleteAsync();

                var model = new SearchData
                {
                    Posts = posts,
                    People = people,
                    Pages = pages,
                    Events = events,
                    Groups = groups,
                    Feed = feed
                };

                return View(model);
            }
        }
    }
}